<!DOCTYPE html>
<html>
<head>
    <:include file="../common/css.html" title="账号"/>

</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card card-box-shadow">
    	<div class="layui-card-body">
    	    <!-- 表格工具栏 -->
            <form class="layui-form toolbar" lay-filter="sszgTbSearchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">类型：</label>
                        <div class="layui-input-inline mr0">
                            <select name="type" xm-select="type" lay-filter="type" lay-verType="tips"  lay-verify="" lay-search>
                                <option value="">请选择</option>
                                <option value="车队">车队</option>
                                <option value="司机">司机</option>
                                <option value="平台用户">平台用户</option>
                                <option value="货代">货代</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">账号：</label>
                        <div class="layui-input-inline mr0">
                            <input name="username" class="layui-input search_key" type="search" placeholder="账号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">名称：</label>
                        <div class="layui-input-inline mr0">
                            <input name="nickName" class="layui-input search_key" type="search" placeholder="名称"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" lay-filter="sszgTbSearch" id="sszgTbSearch" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </form>
	        <!-- 数据表格 -->
        	<table id="sszgTable" lay-filter="sszgTable"></table>
        </div>
    </div>
</div>

<!-- js部分 -->
<:include file="../common/js.html"/>
<script type="text/javascript">
layui.use(['layer', 'form', 'table', 'tableX', 'util', 'admin','xmSelect','formX','dropdown','laydate'], function () {
let $ = layui.jquery;
let layer = layui.layer;
let form = layui.form;
let table = layui.table;
let tableX = layui.tableX;
let util = layui.util;
let admin = layui.admin;
let formX = layui.formX;
let xmSelect = layui.xmSelect;
let laydate = layui.laydate;

// 渲染表格
let insTb = tableX.render({
    elem: '#sszgTable'
    ,url: 'sszg/page'
    ,page: true
    ,height: 'full-100'
    ,limits: [10,20,30,50,80,100,200]
    ,limit: 30 //每页默认显示的数量
    ,toolbar: ['<p>',
        <% if(so.hasPermission("oa:sszg:save")){ %>
        '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
        <% } %>
        <% if(so.hasPermission("oa:sszg:remove")){ %>
        '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>',
        <% } %>
        '<button lay-event="thaw" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe640;</i>解冻</button>',
        '</p>'].join('')
    ,cellMinWidth: 100
    ,cols: [[
        {type: 'checkbox'}
        ,{type: 'numbers'}
        ,{field: "type",  title: "类型", sort: false, hide:false }
        ,{field: "nickName",  title: "名称", sort: false, hide:false }
        ,{field: "username",  title: "账号", sort: false, hide:false }
        ,{field: "password",  title: "密码", sort: false, hide:false }
        ,{field: "createTime",  title: "创建时间", sort: false, hide:true ,templet: function (d) {
                return util.toDateString(d.createTime);
            }
        }
        ,{field: "createUser",  title: "创建人", sort: false, hide:true }
    ]]
});

// 搜索
form.on('submit(sszgTbSearch)', function (data) {
    insTb.reload({where: data.field, page: {curr: 1}});
    return false;
});

form.on('select(type)', function(data){
    $("#sszgTbSearch").click();
});

$('.search_key').bind('keypress',function(event){
    if(event.keyCode == "13") {
        $("#sszgTbSearch").click();
    }
});


/* 表格头工具栏点击事件 */
table.on('toolbar(sszgTable)', function (obj) {
    if ('thaw' === obj.event) { // 添加
        let checkRows = table.checkStatus('sszgTable');
        if (!checkRows || !checkRows.data || 0 === checkRows.data.length) {
            return layer.msg('请选择要解冻的账号', {icon: 2, anim: 6});
        }
        let ids =""
        checkRows.data.map(function (d) {
            ids += d.userId + ",";
        });
        if(ids){
            ids = ids.substr(0, ids.length - 1)
        }
        doThaw({ids: ids});
    }
});


// 删除
function doThaw(t_data) {
    admin.req('sszg/doThaw', t_data, function (res) {
        if (0 === res.code) {
            layer.msg(res.msg, {icon: 1});
            insTb.reload({page: {curr: 1}});
        } else {
            layer.msg(res.msg, {icon: 2, anim: 6});
        }
    }, 'post');
}
});
</script>
</body>
</html>
